package com.example.test.util;

import org.apache.poi.hwpf.converter.WordToHtmlConverter;
import org.apache.poi.hwpf.usermodel.Picture;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

import java.util.Base64;

public class ImageConverter extends WordToHtmlConverter {

	public ImageConverter(Document document) {
		super(document);
	}
	@Override
	protected void processImageWithoutPicturesManager(Element currentBlock, boolean inlined, Picture picture){
		Element imgNode = currentBlock.getOwnerDocument().createElement("img");
		StringBuffer sb = new StringBuffer();
		sb.insert(0, "data:image/png;base64,");
		sb.append(Base64.getMimeEncoder().encodeToString(picture.getRawContent()));
		imgNode.setAttribute("src", sb.toString());
		currentBlock.appendChild(imgNode);
	}
}		